package com.hzhc.controller.wxapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.TrainPlanDetailService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.StringUtils;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.TrainPlanDetailVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wuxiaoke
 * @description app 装车理货控制器
 * @date 2024/6/5 上午9:41
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
public class WxApiCntrZcTallyController  extends BaseController {

    private final TrainPlanDetailService detailService;

    /**
     * 装车理货列表 (出场)
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getAllTrainPlanDetail")
    @ResponseBody
    public ResultUtil<List<TrainPlanDetailVo>> getAllTrainPlanDetail(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanDetailVo> list = new ArrayList<>();
        if (vo.getIsZzt()==0){
            list = detailService.getAllTrainPlanDetail(page,vo);//非直装
        }else{
            list = detailService.getZzTrainPlanDetail(page,vo);//直装
        }
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * ipad 装车理货
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/cntrZcTallyIpad")
    @SysTemLog(operModul = "装车理货", operType = "理货", operDesc = "装车理货功能", modular = "APP")
    public ResultUtil<T> carTallyIpad(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        UserDto userMember = TokenUtil.getUserMember(request);
        vo.setMemberId(userMember.getId());
        vo.setUserName(userMember.getRealname());
        vo.setAccesspath("APP端");
        if (StringUtils.isNull(vo.getIsRectified()) || vo.getIsRectified()==0){//非待整改装车
            return detailService.carTally(vo);
        }else{//待整改
            return detailService.carTallyDzg(vo);
        }

    }

}
